class_name SustainedSoundEmitter extends Node3D

@export var emit_separation:int = 7
@export var velocity:Vector3 = Vector3(0.0, 0.0, 340.0)
@export var sound:AudioStream

var emitting = false
var separation_ticks:int = 0
var collider_container:Node

func start_emit():
	emitting = true

func stop_emit():
	emitting = false

func _ready() -> void:
	collider_container = Node.new()
	add_child(collider_container)

func _physics_process(delta: float) -> void:
	if separation_ticks <= 0:
		separation_ticks = emit_separation
		var new_collider:SoundCollider = SoundCollider.new()
		collider_container.add_child(new_collider)
		new_collider.sound = sound
		new_collider.velocity = velocity
		new_collider.sound_emmited = true
		new_collider.position = global_position
		new_collider = null
	if emitting:
		separation_ticks -= 1
